RM.Pages.Functions.MyReservations_Reservation_Cancel_Cancel = function(){
    Ext.MessageBox.confirm(
        RM.Translate.Admin.MyReservations.Reservation.Cancel.Confirm,
        RM.Translate.Admin.MyReservations.Reservation.Cancel.AreYouSureYouWantToCancelThisReservation,
        function(buttonID, tab){
            if (buttonID !== 'yes') {
                return;
            }
            myMask = new Ext.LoadMask('content-panel', {msg:RM.Translate.Common.PleaseWait});
            myMask.show();
            Ext.Ajax.request({
                url : RM.Common.AssembleURL({
                    controller: 'MyReservations_Cancel',
                    action: 'cancelJson'
                }),
                params: {
                    reservation_id: RM.Pages.Reservations_Edit_ReservationID
                },
                method: 'POST',
                success: function(responseObject) {
                    myMask.hide();
                    RM.Pages.Functions.Reservations_ListJson_Request();
                },
                failure: function() {
                    Ext.Msg.alert('Status', RM.Translate.Common.UnableToShow);
                    myMask.hide();
                }
            });
        }
    );
}

RM.Pages.Functions.MyReservations_Reservation_Cancel_Load = function(){
    myMask = new Ext.LoadMask('content-panel', {msg:RM.Translate.Common.PleaseWait});
    myMask.show();
    Ext.Ajax.request({
        url : RM.Common.AssembleURL({
            controller: 'MyReservations_Cancel',
            action: 'loadJson'
        }),
        params: {
            reservation_id: RM.Pages.Reservations_Edit_ReservationID
        },
        method: 'POST',
        success: function(responseObject) {
            var data = Ext.util.JSON.decode(responseObject.responseText);
            if (data.success == false) {
                var errorMessage = data.message;

                if (data.status !== 2) {
                    errorMessage = RM.Translate.Admin.MyReservations.Reservation.Cancel.Error+': '+errorMessage;
                }

                Ext.getCmp('rm_myreservation_reservation_cancel_panel').body.update(
                    RM.Pages.MyReservations_Reservation_Cancel_Template_Error.applyTemplate({message: errorMessage})
                );
            } else {
                Ext.getCmp('rm_myreservation_reservation_cancel_panel').body.update(
                    RM.Pages.MyReservations_Reservation_Cancel_Template.applyTemplate(data.reservation)
                );
            }
            myMask.hide();
        },
        failure: function() {
            Ext.Msg.alert('Status', RM.Translate.Common.UnableToShow);
            myMask.hide();
        }
    });
}

RM.Pages.MyReservations_Reservation_Cancel_Template = new Ext.XTemplate(
    '<table width="100%" cellpadding="5" cellspacing="5">',
        '<tr>',
            '<td width="40%"><b>'+RM.Translate.Admin.MyReservations.Reservation.Cancel.ReservationID+':</b></td>',
            '<td width="60%">{id}</td>',
        '</tr>',
        '<tr>',
            '<td width="40%"><b>'+RM.Translate.Admin.MyReservations.Reservation.Cancel.MadeOn+':</b></td>',
            '<td width="60%">{cancel_request}</td>',
        '</tr>',
        '<tr>',
            '<td><b>'+RM.Translate.Admin.MyReservations.Reservation.Cancel.TotalPaid+':</b></td>',
            '<td>{total_paid}</td>',
        '</tr>',
        '<tr>',
            '<td colspan="2"><input type="button" onclick="RM.Pages.Functions.MyReservations_Reservation_Cancel_Cancel()" value="Cancel Reservation" /></td>',
        '</tr>',
    '</table>'
);

RM.Pages.MyReservations_Reservation_Cancel_Template_Error = new Ext.XTemplate(
    '<table width="100%" cellpadding="5" cellspacing="5">',
        '<tr>',
            '<td><b>{message}</b></td>',
        '</tr>',
    '</table>'
);

RM.Pages.MyReservations_Reservation_Cancel = new Ext.Panel({
    id: 'rm_myreservation_reservation_cancel_panel',
    title: RM.Translate.Admin.MyReservations.Reservation.Cancel.Tabtitle,
    bodyStyle : "padding:10px",
    autoScroll: true,
    border: false,
    listeners: {
        'beforeshow' : function(){
            RM.Pages.Functions.MyReservations_Reservation_Cancel_Load();
            return true;
        }
    }
});

RM.Pages.Reservations_Edit_TabPanel.add(RM.Pages.MyReservations_Reservation_Cancel);